//
//  WeiboCell.m
//  微博
//
//  Created by zxy on 2018/12/21.
//  Copyright © 2018 zxy. All rights reserved.
//

#import "WeiboCell.h"
#import "WeiBoPictureView.h"

@interface WeiboCell()
/*头像*/
@property (weak, nonatomic) IBOutlet UIImageView *profileImageView;
/*友好名称*/
@property (weak, nonatomic) IBOutlet UILabel *nameL;
/*创建日期和来源*/
@property (weak, nonatomic) IBOutlet UILabel *createAtAndSourceL;
;
/*微博内容*/
@property (weak, nonatomic) IBOutlet UILabel *textL;
/*转发-评论-点赞按钮*/
@property (weak, nonatomic) IBOutlet UIButton *forwardBtn;
@property (weak, nonatomic) IBOutlet UIButton *commitBtn;
@property (weak, nonatomic) IBOutlet UIButton *likeBtn;

@property(nonatomic,strong)WeiBoPictureView *pictureView;


@end
@implementation WeiboCell

-(WeiBoPictureView *)pictureView{
    if(!_pictureView){
        _pictureView = [[WeiBoPictureView alloc]init];
        [self.contentView addSubview:_pictureView];
    }
    return _pictureView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

-(void)setModel:(StatuesModel *)model{
    _model = model;
    [self.profileImageView sd_setImageWithURL:[NSURL URLWithString:model.user.profile_image_url]];
    self.nameL.text = model.user.name;
    self.createAtAndSourceL.text = [NSString stringWithFormat:@"%@ %@",model.created_at,model.source];
    self.textL.text = model.text;
    [self.forwardBtn setTitle:model.reposts_count forState:UIControlStateNormal];
    [self.commitBtn setTitle:model.comments_count forState:UIControlStateNormal];
    [self.likeBtn setTitle:model.attitudes_count forState:UIControlStateNormal];
    
    if(model.pic_urls.count > 0){
        self.pictureView.hidden = NO;
        self.pictureView.frame = model.picBgViewFrame;
        self.pictureView.model = model;
    }else{
        self.pictureView.hidden = YES;
        self.pictureView.frame = CGRectMake(0, 0, 0, 0);
    }
}

-(void)setFrame:(CGRect)frame{
     frame.size.height -=picMargin;
    [super setFrame:frame];
}

@end
